<div class="page-header">
    <h1><?php echo $this->titulo; ?></h1>
</div>

<form class="form-inline" role="form">
    <div class="form-group"> 
        <div class="input-group">
            <label class="sr-only" for="dtfiltro">Data</label>
            <input type="text" class="form-control" id="dtfiltro" name="dtfiltro" placeholder="Data" value="<?php echo $this->dtfiltro; ?>">
        </div>
    </div>
    <div class="form-group">
        <div class="input-group">
            <?php
            
                $query = 'SELECT SQL_CACHE USU_ID,USU_NOM FROM USUARIOS WHERE USU_STA = 1 ORDER BY USU_NOM ASC';
                $f_cur = $this->db->fetchAll($query);

                $html = '<select id="cbfiltro" name="cbfiltro" class="form-control" >';
                $html .= '<option value="">Todos usuários</option>';
                foreach($f_cur as $r){   
                    $select = $this->cbfiltro == $r['USU_ID'] ? 'selected':''; 
                    $html .= '<option '.$select.' value="'.$r['USU_ID'].'">'.$r['USU_NOM'].'</option>'; 
                }
                $html .= '</select>';
                echo $html;
                
            ?>
        </div>
    </div>
    <div class="form-group">
        <div class="input-group">
            <?php
            
                $query = 'SELECT SQL_CACHE MOD_NOM,MOD_ARQ FROM MODULOS WHERE MOD_STA = 1 ORDER BY MOD_NOM ASC';
                $f_cur = $this->db->fetchAll($query);

                $html = '<select id="mdfiltro" name="mdfiltro" class="form-control" >';
                $html .= '<option value="">Todos módulos</option>';
                foreach($f_cur as $r){   
                    $select = $this->mdfiltro == $r['MOD_ARQ'] ? 'selected':''; 
                    $html .= '<option '.$select.' value="'.$r['MOD_ARQ'].'">'.$r['MOD_NOM'].'</option>'; 
                }
                $html .= '</select>';
                echo $html;
                
            ?>
        </div>
    </div>
    <div class="form-group">
        <div class="input-group">
            <?php
            
                $f_cur = array('index','edit','delete');

                $html = '<select id="acfiltro" name="acfiltro" class="form-control" >';
                $html .= '<option value="">Todas ações</option>';
                foreach($f_cur as $r){   
                    $select = $this->acfiltro == $r ? 'selected':''; 
                    $html .= '<option '.$select.' value="'.$r.'">'.$r.'</option>'; 
                }
                $html .= '</select>';
                echo $html;
                
            ?>
        </div>
    </div>
    <div class="form-group">
        <?php
            $arr = dominio::tpoSistemas();
            $html = '';
            foreach($arr as $key => $value){   
                $html .= '<label>'.elemform::radio('tpfiltro','tpfiltro',$key,$this->tpfiltro).$value.'</label>&nbsp;';
            }
            if(count($arr) > 1) echo '<div class="input-group">  '.$html.'</div>';                
        ?>            
        
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-default">
            <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
            Pesquisar
        </button>
    </div>    
</form>

<div class="table-responsive">
    <table id="tlist" class="table table-striped table-hover">
        <thead>
            <tr>
                <th>Data</th>
                <th>Usuário</th>
                <th>IP</th>
                <th>Módulo</th>
                <th>Ação</th>
                <th>Cod. ID</th>
                <th>Painel</th>
                <th>Forma</th>
                <th class="bc">&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->result as $row) { ?>
                <tr>
                    <td><?php echo Datetools::amd_dma($row['ACE_DAT']).' '.$row['ACE_HOR']; ?></td>
                    <td><?php echo $row['USU_NOM']; ?></td>
                    <td><?php echo $row['ACE_IP']; ?></td>
                    <td><?php echo $row['ACE_CTL']; ?></td>
                    <td><?php echo $row['ACE_ACT']; ?></td>
                    <td><?php echo $row['ACE_COD']; ?></td>
                    <td><?php echo dominio::getTpoSistemas($row['ACE_TPO']); ?></td>
                    <td><?php echo strlen($row['ACE_PST']) > 0 ? 'POST':'GET'; ?></td>
                    <td class="bc">
                        <?php if($this->per_edt){?><a class="btn btn-sm btn-primary" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => $row['ACE_ID'])); ?>"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> Registro</a><?php }?>
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
</div>
<script>dataPicker($('#dtfiltro'));</script>
